<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        var jack = {name:"jack",age:20,_school:'',_height:''}
        Object.defineProperties(jack,{
            school:{
                get:function(){
                    console.log('获取_school的值')
                    return this._school
                },
                set:function(v){
                    console.log('设置_school的值')
                    if(v=="新东方烹饪"){
                        console.log('没有这个学校')
                    }else{
                        this._school = v.trim()
                    }
                   
                }
            },
            height:{
                get(){
                    return this._height
                },
                set(v){
                    this._height = v.replace("cm",'')
                }
            }
        })
    </script>
</body>

</html>